package com.jjmmbb.jxSudoku;

import java.util.ArrayList;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.adb.adapter.StageAdapter;
import com.adb.dao.GameDataManager;
import com.adb.entity.GameData;

public class StageListActivity extends BaseActivity implements
		OnItemClickListener {
	TextView tv_title;
	ListView lv_stage;

	String ini_data = "0";
	StageAdapter adapter = null;

	GameDataManager gdm = new GameDataManager();

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.stage_list);
		tv_title = (TextView) findViewById(R.id.sl_tv_title);
		lv_stage = (ListView) findViewById(R.id.sl_lv_stage);

		lv_stage.setOnItemClickListener(this);

		ini();
		setNightMode();
	}

	public void ini() {
		Bundle bundle = this.getIntent().getExtras();
		int stage = bundle.getInt("stage");

		switch (stage) {
		case 1:
			tv_title.setText(R.string.main_easy);
			break;
		case 2:
			tv_title.setText(R.string.main_expert);
			break;
		case 3:
			tv_title.setText(R.string.main_master);
			break;
		}

		Comm.listGameData = (ArrayList<GameData>) gdm.getGameDataListAsStage(
				this, stage);
		// 加载数据
		if (null == Comm.listGameData) {
			return;
		}

		adapter = new StageAdapter(this, Comm.listGameData);
		lv_stage.setAdapter(adapter);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// 设置数独数据
		Comm.currentGameData = Comm.listGameData.get(position);
		gotoActivity(GameActivity.class);
	}

	@Override
	protected void onResume() {
		if (null != adapter) {
			adapter.notifyDataSetChanged();
		}
		super.onResume();
	}

}
